# -*- coding:utf-8 -*-
import pymysql

# 建立连接
con = pymysql.connect(
    host="127.0.0.1",
    port=3306,
    user="root",
    password="15096962415",
    db="db5"
)

# 建立游标，使用python给mysql传递命令
cur = con.cursor()

try:
    sql1 = "insert into student value (6, '小明', 67, 40, 43);"
    sql2 = "insert into student value (7, '小成', 67, 40, 43);"
    sql3 = "insert into student value (8, '小丁', 67, 40, 43);"
    sql4 = "insert into student value (9, '小邓', 67, 40, 43);"
    cur.execute(sql1)
    cur.execute(sql2)
    cur.execute(sql3)
    cur.execute(sql4)
    con.commit()
    print("完成")
except:
    print("执行异常")
    con.rollback()        # 事务回滚

sql5 = "select * from student;"
cur.execute(sql5)
value = cur.fetchall()       # fetchall 获取所有的记录


for i in value:
    print(i)

cur.close()   # 关闭游标
con.close()   # 关闭连接
